/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objects;

import OBJ_Loader.Face;
import OBJ_Loader.ObjManager;
import graphic.Color;
import graphic.Graphic;
import org.lwjgl.util.vector.Vector3f;

/**
 *
 * @author Marcin
 */
public class Wall {
    public float height;
    public float width;
    public float stx,sty,stz;
    public float edx,edy,edz;
    public Color col;
    public int ID;
    
    
    public Triangle[] list= new Triangle[10];
    
    public Wall(Vector3f start, Vector3f end, float height,float width,Color col){
        stx=start.x;
        sty=start.y;
        stz=start.z;
        edx=end.x;
        edy=end.y;
        edz=end.z;
        this.col=col;
        this.height=height;
        this.width=width;
        //ID=ObjManager.getID();
        create();
    }
    public void draw(){
            for(Triangle t : list)
                Graphic.e.drawTNn(t);
    }
    public void create(){
        float z= edz-stz;
        float x= edx-stx;
        
        float z1=(float) ((width*z)/(Math.sqrt(x*x+z*z)));
        float x1=(z==0?width:x*z1/z);
        
        list[0] = new Triangle(stx-z1,sty,stz+x1,  edx-z1,sty,       edz+x1,  stx-z1,sty+height,stz+x1);
        list[1] = new Triangle(edx-z1,sty,edz+x1,  edx-z1,sty+height,edz+x1,  stx-z1,sty+height,stz+x1);
        list[2] = new Triangle(stx+z1,sty,stz-x1  ,stx+z1,sty+height,stz-x1,  edx+z1,sty,edz-x1);
        list[3] = new Triangle(edx+z1,sty,edz-x1  ,stx+z1,sty+height,stz-x1  ,edx+z1,sty+height,edz-x1);
        list[4] = new Triangle(stx-z1,sty,stz+x1  , stx-z1,sty+height,stz+x1, stx+z1,sty,stz-x1);
        list[5] = new Triangle(stx+z1,sty,stz-x1  , stx-z1,sty+height,stz+x1, stx+z1,sty+height,stz-x1);
        
        list[6] = new Triangle(edx-z1,edy,edz+x1  , edx+z1,edy,edz-x1, edx-z1,edy+height,edz+x1);
        list[7] = new Triangle(edx+z1,edy,edz-x1  , edx+z1,edy+height,edz-x1, edx-z1,edy+height,edz+x1);
        
        list[8] = new Triangle(stx-z1,sty+height,stz+x1 ,  edx-z1,sty+height,edz+x1, edx+z1,edy+height,edz-x1);
        list[9] = new Triangle(stx-z1,sty+height,stz+x1 ,  edx+z1,sty+height,edz-x1, stx+z1,sty+height,stz-x1);
        for(Triangle t:list)
            t.calcNormal();
        
    }
    public void compile(){
        Graphic.e.startList(ID);
        {
            Graphic.e.startDrawT();
            for(Triangle t : list){
                Graphic.e.drawTNn(t);
            }            
            Graphic.e.endDraw();
        }
        Graphic.e.endList();
    }
}
